//package com.plian.system.service.fr.budgetfeedback.impl;
//
//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
//import com.baomidou.mybatisplus.core.metadata.IPage;
//import com.google.common.base.Joiner;
//import com.itextpdf.text.pdf.AcroFields;
//import com.itextpdf.text.pdf.BaseFont;
//import com.itextpdf.text.pdf.PdfReader;
//import com.itextpdf.text.pdf.PdfStamper;
//import com.plian.Tools.*;
//import com.plian.Tools.office.WordUtil;
//import com.plian.Tools.pagedata.PageData;
//import com.plian.system.config.RedisUtils;
//import com.plian.system.constant.fr.BudgetFeedbackMattersConstant;
//import com.plian.system.constant.sys.FormStatusConstant;
//import com.plian.system.constant.sys.FormTypeConstant;
//import com.plian.system.dao.sys.file.FileDao;
//import com.plian.system.dao.sys.orgzation.OrgzationDao;
//import com.plian.system.dao.sys.user.UserDao;
//import com.plian.system.dto.fr.budgetfeedback.FullBudgetFeedbackMattersDTO;
//import com.plian.system.entity.fr.budgetfeedback.FullBudgetFeedbackMatters;
//import com.plian.system.entity.fr.budgetfeedback.FullBudgetFeedbackMattersDetail;
//import com.plian.system.entity.sys.Message;
//import com.plian.system.mapper.fr.budgetfeedback.FullBudgetFeedbackMattersDetailMapper;
//import com.plian.system.mapper.fr.budgetfeedback.FullBudgetFeedbackMattersMapper;
//import com.plian.system.model.CommonCode;
//import com.plian.system.model.ListResult;
//import com.plian.system.model.ObjResult;
//import com.plian.system.model.R;
//import com.plian.system.config.exception.MyRuntimeException;
//import com.plian.system.mybatis.base.BaseServiceImpl;
//import com.plian.system.mybatis.search.SearchEntity;
//import com.plian.system.mybatis.search.SearchParamEntiy;
//import com.plian.system.mybatis.support.Condition;
//import com.plian.system.mybatis.support.Query;
//import com.plian.system.properties.GzwProperties;
//import com.plian.system.service.fr.budgetfeedback.IFullBudgetFeedbackMattersDetailService;
//import com.plian.system.service.fr.budgetfeedback.IFullBudgetFeedbackMattersService;
//import com.plian.system.service.sys.code.IFormCodeService;
//import com.plian.system.service.sys.file.FileService;
//import com.plian.system.service.sys.message.IMessageService;
//import com.plian.system.service.sys.user.ISysUserService;
//import com.plian.system.service.wf.FormWorkflowService;
//import com.plian.system.vo.fr.budgetfeedback.FullBudgetFeedbackMattersDetailVO;
//import com.plian.system.vo.fr.budgetfeedback.FullBudgetFeedbackMattersVO;
//import com.plian.system.wrapper.fr.budgetfeedback.FullBudgetFeedbackMattersDetailWrapper;
//import com.plian.system.wrapper.fr.budgetfeedback.FullBudgetFeedbackMattersWrapper;
//import lombok.AllArgsConstructor;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.commons.io.FileUtils;
//import org.apache.commons.lang.exception.ExceptionUtils;
//import org.springframework.beans.BeanUtils;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.core.env.Environment;
//import org.springframework.core.io.DefaultResourceLoader;
//import org.springframework.core.io.ResourceLoader;
//import org.springframework.mock.web.MockMultipartFile;
//import org.springframework.stereotype.Service;
//import org.springframework.transaction.annotation.Transactional;
//import org.springframework.web.multipart.MultipartFile;
//
//import javax.annotation.Resource;
//import javax.servlet.http.HttpServletResponse;
//import java.io.*;
//import java.nio.file.Files;
//import java.nio.file.Path;
//import java.nio.file.Paths;
//import java.nio.file.StandardCopyOption;
//import java.util.*;
//import java.util.stream.Collectors;
//
///**
// * 服务实现类 合计表和子表关联关系表
// *
// * @author
// * @since 2019-09-27
// */
//@Slf4j
//@Service
//@AllArgsConstructor
//public class FullBudgetFeedbackMattersServiceImpl extends BaseServiceImpl<FullBudgetFeedbackMattersMapper, FullBudgetFeedbackMatters> implements IFullBudgetFeedbackMattersService {
//
//
//    private ISysUserService userService;
//
//    private FormWorkflowService formWorkflowService;
//
//    private UserDao userDao;
//
//    private final FileService fileService;
//
//    @Autowired
//    private OrgzationDao orgzationDao;
//
//    private Environment environment;
//
//    private RedisUtils redisUtils;
//
//    private IFormCodeService formCodeService;
//
//    @Autowired
//    private FileDao fileDao;
//
//    @Resource
//    private FullBudgetFeedbackMattersDetailMapper mattersDetailMapper;
//
//    private IMessageService messageService;
//
//    private final FullBudgetFeedbackMattersWrapper mattersWrapper;
//
//    private final FullBudgetFeedbackMattersDetailWrapper mattersDetailWrapper;
//
//    private final IFullBudgetFeedbackMattersDetailService fullBudgetFeedbackMattersDetailService;
//
//    private GzwProperties gzwProperties;
//
//
//    /**
//     * 保存反馈意见
//     *
//     * @param budgetFeedbackMattersVO
//     * @return boolean
//     **/
//    @Override
//    @Transactional(rollbackFor = Throwable.class)
//    public R submit(FullBudgetFeedbackMattersVO budgetFeedbackMattersVO) {
//        try {
//            //相关责任科室
//            FullBudgetFeedbackMatters feedbackMatters = mattersWrapper.voToEntity(budgetFeedbackMattersVO);
//            if (budgetFeedbackMattersVO.getId() == null) {
//                feedbackMatters.setCode(formCodeService.getCode(FormTypeConstant.FULL_BUDGET_FEEDBACK_MATTERS_GZ));
//                feedbackMatters.setFormType(String.valueOf(FormTypeConstant.FULL_BUDGET_FEEDBACK_MATTERS_GZ));
//                feedbackMatters.setStatus(BudgetFeedbackMattersConstant.BUDGET_NOT_AGGREGATED);
//                //feedbackMatters.setDeliveryTime(new Date());
//                feedbackMatters.setFeedbackTime(new Date());
//                feedbackMatters.setCreateCompanyId(TokenUtil.getTokenOrgId());
//            }
//            super.saveOrUpdate(feedbackMatters);
//            //detail
//            if (CollectionUtil.isNotEmpty(budgetFeedbackMattersVO.getMattersDetails())) {
//                for (FullBudgetFeedbackMattersDetailVO matters : budgetFeedbackMattersVO.getMattersDetails()) {
//                    FullBudgetFeedbackMattersDetail mattersDetail = mattersDetailWrapper.voToEntity(matters);
//                    if (StringUtil.isEmpty(mattersDetail.getId())) {
//                        mattersDetail.setId(UuidUtil.get32UUID());
//                        mattersDetail.setMid(feedbackMatters.getId().toString());
//                        mattersDetail.setFeedbackOfficeId(Long.parseLong(budgetFeedbackMattersVO.getOfficeId()));
//                        mattersDetail.setFeedbackOfficeName(budgetFeedbackMattersVO.getOfficeName());
//                        mattersDetail.setFeedbackMatters(mattersDetail.getFeedbackMatters());
//                        mattersDetail.setCreateUser(TokenUtil.getTokenUserId());
//                        mattersDetail.setCreateTime(new Date());
//                        mattersDetail.setUpdateUser(TokenUtil.getTokenUserId());
//                        mattersDetail.setUpdateTime(new Date());
//                        mattersDetailMapper.insert(mattersDetail);
//                    } else {
//                        mattersDetail.setUpdateUser(TokenUtil.getTokenUserId());
//                        mattersDetail.setUpdateTime(new Date());
//                        mattersDetail.setFeedbackMatters(mattersDetail.getFeedbackMatters());
//                        mattersDetail.setIsDeleted(mattersDetail.getIsDeleted());
//                        mattersDetailMapper.updateById(mattersDetail);
//
//                    }
//                }
//            }
//
//        } catch (Exception e) {
//            log.error("error:save-" + e.getMessage());
//            throw new MyRuntimeException(new ObjResult("保存失败！"));
//        }
//        return R.success();
//    }
//
//    @Override
//    public ListResult listPage(Query query) {
//        if (query.getAscs() == null && query.getDescs() == null) {
//            query.setDescs("create_time");
//        }
//        List<SearchEntity> entityList = query.getSearch();
//        QueryWrapper<FullBudgetFeedbackMatters> queryWrapper = SearchParamEntiy.getQueryWrapper(
//                Condition.getQueryWrapper(new FullBudgetFeedbackMatters()), entityList
//        );
////        User user = userService.getById(TokenUtil.getTokenUserId());
////        if (user.getOfficeId() == null) {
////            queryWrapper.in("status", Func.toLongList(StringPool.COMMA, BudgetFeedbackMattersConstant.BUDGET_QY_STATUS));
////        }
////        if (!Optional.ofNullable(query.getFlag()).isPresent() || query.getFlag() != 1) {
////            queryWrapper.eq("create_company_id", TokenUtil.getTokenOrgId());
////        }
//        IPage<FullBudgetFeedbackMatters> pages = page(Condition.getPage(query), queryWrapper);
//        ListResult<FullBudgetFeedbackMatters> listResult = new ListResult<>(CommonCode.SUCCESS);
//        List<FullBudgetFeedbackMatters> records = filterPageData1(pages.getRecords());
//        listResult.setList(records);
//        listResult.setTotal(Long.valueOf(records.size()).intValue());
//        return listResult;
//    }
//
//    /**
//     * 数据过滤，如果单据一直，已汇总，列表只展示会汇总完的
//     **/
//    private List<FullBudgetFeedbackMatters> filterPageData(List<FullBudgetFeedbackMatters> records) {
//        Map<String, List<FullBudgetFeedbackMatters>> map = records.stream().collect(Collectors.groupingBy(FullBudgetFeedbackMatters::getReportId));
//        List<FullBudgetFeedbackMatters> result = new LinkedList<>();
//        for (Map.Entry<String, List<FullBudgetFeedbackMatters>> m : map.entrySet()) {
//            System.out.println("key=" + m.getKey());
//            List<FullBudgetFeedbackMatters> value = m.getValue();
//            List<FullBudgetFeedbackMatters> collect = value.stream().filter(item -> {
//                if (BudgetFeedbackMattersConstant.BUDGET_NOT_ISSUED.equals(item.getStatus()) || BudgetFeedbackMattersConstant.BUDGET_ALREADY_ISSUED.equals(item.getStatus())
//                        || BudgetFeedbackMattersConstant.BUDGET_ALREADY_FEEDBACK.equals(item.getStatus())) {
//                    return true;
//                }
//                return false;
//            }).collect(Collectors.toList());
//            if (CollectionUtil.isEmpty(collect)) {
//                result.addAll(value);
//            }
//            result.addAll(collect);
//        }
//        //倒叙排
//        result = result.stream().sorted(Comparator.comparing(FullBudgetFeedbackMatters::getCreateTime).reversed()).collect(Collectors.toList());
//        return result;
//    }
//
//    private List<FullBudgetFeedbackMatters> filterPageData1(List<FullBudgetFeedbackMatters> records) {
//        try {
//            boolean isGzw = gzwProperties.getIsGzw(TokenUtil.getTokenOrgId());
//            if (!isGzw) {
//                List<FullBudgetFeedbackMatters> total = records.stream().filter(e ->
//                        StringUtil.isNotBlank(e.getRecordCode()) && TokenUtil.getTokenOrgId().equals(e.getUnitId())).collect(Collectors.toList());
//                return total;
//            } else {
//                return records;
//            }
//        } catch (Exception e) {
//            log.error("error:" + e.getMessage());
//        }
//        return records;
//    }
//
//    void updateOther(List<FullBudgetFeedbackMatters> othersFeedbackMatters, Integer status) {
//        if (CollectionUtil.isNotEmpty(othersFeedbackMatters)) {
//            othersFeedbackMatters.forEach(item -> {
//                item.setStatus(status);
//                updateById(item);
//            });
//        }
//
//    }
//
//    /**
//     * 保存/保存下发/财管处汇总
//     *
//     * @param budgetFeedbackMattersVO
//     * @return
//     */
//    @Transactional(rollbackFor = Throwable.class)
//    @Override
//    public R saveSend(FullBudgetFeedbackMattersVO budgetFeedbackMattersVO) {
//        try {
//            //单子id
//            String reportId = budgetFeedbackMattersVO.getReportId();
//            //保存财管处的意见
//            FullBudgetFeedbackMatters summaryMatters = mattersWrapper.voToEntity(budgetFeedbackMattersVO);
//
//            //查询出其它为汇总的
//            List<FullBudgetFeedbackMatters> othersFeedbackMatters = baseMapper.selectList(new LambdaQueryWrapper<FullBudgetFeedbackMatters>()
//                    .eq(FullBudgetFeedbackMatters::getStatus, BudgetFeedbackMattersConstant.BUDGET_NOT_AGGREGATED));
//
//
//            if (budgetFeedbackMattersVO.getId() == null) {
//                summaryMatters.setCode(formCodeService.getCode(FormTypeConstant.FULL_BUDGET_FEEDBACK_MATTERS_GZ));
//                summaryMatters.setFormType(String.valueOf(FormTypeConstant.FULL_BUDGET_FEEDBACK_MATTERS_GZ));
//                summaryMatters.setStatus(BudgetFeedbackMattersConstant.BUDGET_NOT_AGGREGATED);
//                summaryMatters.setFeedbackTime(new Date());
//                summaryMatters.setFormType(String.valueOf(FormTypeConstant.FULL_BUDGET_FEEDBACK_MATTERS_GZ));
//                summaryMatters.setCode(formCodeService.getCode(FormTypeConstant.FULL_BUDGET_FEEDBACK_MATTERS_GZ));
//            }
//
//            if (BudgetFeedbackMattersConstant.BUDGET_NOT_ISSUED.equals(budgetFeedbackMattersVO.getFlag())) {
//                //其它处室相关单子更折汇总走
//                updateOther(othersFeedbackMatters, BudgetFeedbackMattersConstant.BUDGET_NOT_ISSUED);
//                //保存
//                summaryMatters.setStatus(BudgetFeedbackMattersConstant.BUDGET_NOT_ISSUED);
//                super.saveOrUpdate(summaryMatters);
//            } else {
//                //其它处室相关单子更折汇总走
//                updateOther(othersFeedbackMatters, BudgetFeedbackMattersConstant.BUDGET_ALREADY_ISSUED);
//
////                String recode = "邢国资财评预备字(" + budgetFeedbackMattersVO.getYear() + ")" + LocalDate.now().getMonthValue() + "号";
//                PageData filingCode = formCodeService.getNoFormatFilingCode((FormTypeConstant.FULL_BUDGET_FEEDBACK_MATTERS_GZ));
//                if (filingCode != null) {
//                    String recode = "邢国资财评预备字(" + filingCode.getString("year") + ")" + filingCode.getString("codeNumber") + "号";
//                    summaryMatters.setRecordCode(recode);
//                }
//                summaryMatters.setRecordTime(new Date());
//                //保存下发
//                summaryMatters.setStatus(BudgetFeedbackMattersConstant.BUDGET_ALREADY_ISSUED);
//                summaryMatters.setDeliveryTime(new Date());
//
//                super.saveOrUpdate(summaryMatters);
//                //下发消息
//                sendCompanyMessage(summaryMatters);
//
//            }
//
//            //反馈意见
//            List<FullBudgetFeedbackMattersDetail> detailsList = new LinkedList<>();
//
//            if (CollectionUtil.isNotEmpty(budgetFeedbackMattersVO.getMattersDetails())) {
//
//                for (FullBudgetFeedbackMattersDetail matters : budgetFeedbackMattersVO.getMattersDetails()) {
//                    FullBudgetFeedbackMattersDetail mattersDetail = new FullBudgetFeedbackMattersDetail();
//                    if (StringUtil.isBlank(matters.getId())) {
//                        mattersDetail.setId(UuidUtil.get32UUID());
//                        mattersDetail.setFeedbackOfficeId(Long.parseLong(budgetFeedbackMattersVO.getOfficeId()));
//                        mattersDetail.setFeedbackOfficeName(budgetFeedbackMattersVO.getOfficeName());
//                    } else {
//                        mattersDetail.setId(matters.getId());
//                        mattersDetail.setFeedbackOfficeId(matters.getFeedbackOfficeId());
//                        mattersDetail.setFeedbackOfficeName(matters.getFeedbackOfficeName());
//                    }
//                    mattersDetail.setMid(summaryMatters.getId().toString());
//                    mattersDetail.setFeedbackMatters(matters.getFeedbackMatters());
//                    mattersDetail.setCreateTime(new Date());
//                    mattersDetail.setCreateUser(TokenUtil.getTokenUserId());
//                    mattersDetail.setUpdateTime(new Date());
//                    mattersDetail.setUpdateUser(TokenUtil.getTokenUserId());
//                    detailsList.add(mattersDetail);
//                }
//            }
//            fullBudgetFeedbackMattersDetailService.saveOrUpdateBatch(detailsList);
//            try {
//                //生成备案表附件
//                downPdf(summaryMatters);
//            } catch (Exception e) {
//                log.error("error:备案表生成失败！{}", e);
//            }
//            //忽略预算填报消息
//            setIgnoreMessage(budgetFeedbackMattersVO);
//
//        } catch (Exception e) {
//            log.error("error:save-" + e.getMessage());
//            throw new MyRuntimeException(new ObjResult("汇总失败！"));
//        }
//        return R.success();
//    }
//
//
//    /**
//     * 上报财管处，发送消息
//     *
//     * @param feedbackMatters
//     * @return void
//     **/
//    public void sendFinancialMangMessage(FullBudgetFeedbackMatters feedbackMatters) {
//        List<Message> messages = new ArrayList<>();
//        FullBudgetFeedbackMatters matters = getById(feedbackMatters.getId());
//
//        String orgId = TokenUtil.getTokenOrgId();
//        String userId = TokenUtil.getTokenUserId();
//        try {
//            PageData findbyid = userDao.findbyid(userId);
//            String userName = findbyid.getString("name");
//            //当前登录用户企业信息
//            PageData currOrgInfo = orgzationDao.findbyid(orgId);
//            String isunit = currOrgInfo.getString("isunit");
//            String orgName = currOrgInfo.getString("orgName");
//
//            PageData data = new PageData();
//            data.put("officeId", matters.getOfficeId());
//            data.put("funName", "全面预算");
//            //财管处
//            List<PageData> userByOffice = userDao.findOfficeUserByConfigFunAndOrgId(data);
//            if (CollectionUtil.isNotEmpty(userByOffice)) {
//                for (PageData pageData : userByOffice) {
//                    Message message = Message.builder().formId(matters.getId() + "").orgName(orgName)
//                            .orgId(pageData.getString("orgId")).formType(feedbackMatters.getFormType()).formTypeName("全面预算备案").messageTime(DateUtil.now())
//                            .createUser(pageData.getString("userId")).message("已完成备案意见反馈")
//                            .sendUser(userId).sendUserName(userName).isIgnore(0).build();
//                    messages.add(message);
//                }
//            }
//
//            messageService.saveBatch(messages);
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//
//
//    }
//
//    /**
//     * 下发企业消息
//     *
//     * @param feedbackMatters
//     */
//    public void sendCompanyMessage(FullBudgetFeedbackMatters feedbackMatters) {
//        List<Message> messages = new ArrayList<>();
//        FullBudgetFeedbackMatters matters = getById(feedbackMatters.getId());
//        //当前登陆用户
//        String orgId = TokenUtil.getTokenOrgId();
//        String userId = TokenUtil.getTokenUserId();
//
//        try {
//            PageData findbyid = userDao.findbyid(userId);
//            String userName = findbyid.getString("name");
//            //当前登录用户企业信息
//            PageData currOrgInfo = orgzationDao.findbyid(orgId);
//            String isunit = currOrgInfo.getString("isunit");
//            String orgName = currOrgInfo.getString("orgName");
//
//            PageData data = new PageData();
//            data.put("orgId", orgId);
//            data.put("funName", "全面预算");
//            List<PageData> pageDatas = userDao.findCompanyUserByConfigFunAndOrgId(data);
//            //下发企业的人
//            if (CollectionUtil.isNotEmpty(pageDatas)) {
//                for (PageData pageData : pageDatas) {
//                    Message message = Message.builder().formId(matters.getId() + "").orgName(orgName + "-财务管理与评价处")
//                            .orgId(matters.getUnitId()).formType(feedbackMatters.getFormType()).formTypeName("全面预算备案").messageTime(DateUtil.now())
//                            .createUser(pageData.getString("userId")).message("请完成备案意见反馈")
//                            .sendUser(userId).sendUserName(userName).isIgnore(0).build();
//
//                    messages.add(message);
//                }
//            }
//            messageService.saveBatch(messages);
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//
//    }
//
//    /**
//     * @param budgetFeedbackMattersVO
//     * @return com.plian.system.model.R
//     **/
//    @Transactional(rollbackFor = Throwable.class)
//    @Override
//    public R saveEnterpriseSend(FullBudgetFeedbackMattersVO budgetFeedbackMattersVO) {
//        try {
//            String reportId = budgetFeedbackMattersVO.getReportId();
//            FullBudgetFeedbackMatters matters = baseMapper.selectOne(new LambdaQueryWrapper<FullBudgetFeedbackMatters>()
//                    .eq(FullBudgetFeedbackMatters::getReportId, reportId)
//                    .eq(FullBudgetFeedbackMatters::getStatus, BudgetFeedbackMattersConstant.BUDGET_ALREADY_ISSUED));
//            if (matters == null) {
//                return R.data("未查询到数据", CommonCode.FAIL);
//            }
//            if (BudgetFeedbackMattersConstant.BUDGET_ALREADY_FEEDBACK.equals(budgetFeedbackMattersVO.getFlag())) {
//                //保存并上报
//                matters.setStatus(BudgetFeedbackMattersConstant.BUDGET_ALREADY_FEEDBACK);
//
//                //给财管处发消息
//                sendFinancialMangMessage(matters);
//            } else {
//                //保存
//                matters.setStatus(BudgetFeedbackMattersConstant.BUDGET_ALREADY_ISSUED);
//            }
//            matters.setFormType(String.valueOf(FormTypeConstant.FULL_BUDGET_FEEDBACK_MATTERS_GZ));
//            baseMapper.updateById(matters);
//            /**
//             * 保存内容
//             **/
//
//            List<FullBudgetFeedbackMattersDetailVO> mattersDetailsVO = budgetFeedbackMattersVO.getMattersDetails();
//            if (CollectionUtil.isNotEmpty(mattersDetailsVO)) {
//                for (FullBudgetFeedbackMattersDetail detail : mattersDetailsVO) {
//                    FullBudgetFeedbackMattersDetail currDetail = mattersDetailMapper.selectById(detail.getId());
//                    currDetail.setEnterpriseFeedback(detail.getEnterpriseFeedback());
//                    mattersDetailMapper.updateById(currDetail);
//                    //附件
//                    List<PageData> list_doc = fileDao.findParentId(currDetail.getId());
//                    if (CollectionUtil.isNotEmpty(list_doc)) {
//                        fileDao.del_ParentId(currDetail.getId());
//                    }
//                    detail.getDocList().forEach(item -> {
//                        item.put("itFileName", item.get("fileName"));
//                    });
//                    fileService.saveAll(String.valueOf(currDetail.getId()), detail.getDocList());
//                }
//            }
//
//
//        } catch (Exception e) {
//            log.error("error:saveEnterpriseSend-" + e.getMessage());
//            throw new MyRuntimeException(new ObjResult("保存失败！"));
//        }
//        return R.success();
//    }
//
//
//    @Override
//    public void downPdf(FullBudgetFeedbackMatters matters) {
//        try {
//            if (matters != null && !"".equals(matters)) {
//
//                FullBudgetFeedbackMatters feedbackMatters = getById(matters.getId());
//
//                String mattersDetails = "";
//                List<FullBudgetFeedbackMattersDetail> fullBudgetFeedbackMattersDetails = mattersDetailMapper.selectList(new LambdaQueryWrapper<FullBudgetFeedbackMattersDetail>()
//                        .eq(FullBudgetFeedbackMattersDetail::getMid, matters.getId()));
//                if (CollectionUtil.isNotEmpty(fullBudgetFeedbackMattersDetails)) {
//                    List<String> feedMatters = fullBudgetFeedbackMattersDetails.stream().map(FullBudgetFeedbackMattersDetail::getFeedbackMatters).collect(Collectors.toList());
//                    mattersDetails = Joiner.on(";\n").join(feedMatters);
//                }
//
//                ResourceLoader resourceLoader = new DefaultResourceLoader();
//                File model = File.createTempFile("logo", ".pdf");
//
//                //准备pdf
//                FileUtils.copyInputStreamToFile(resourceLoader.getResource("/pdf/full_budget_business.pdf").getInputStream(), model);
//
//                String fileName = model.getPath();
//                PdfReader reader = new PdfReader(fileName);
//                ByteArrayOutputStream bos = new ByteArrayOutputStream();
//                /* 将要生成的目标PDF文件名称 */
//                PdfStamper ps = new PdfStamper(reader, bos);
//                /* 使用中文字体 */
//                BaseFont bf = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
//                ArrayList<BaseFont> fontList = new ArrayList<BaseFont>();
//                fontList.add(bf);
//
//                /* 取出报表模板中的所有字段 */
//                AcroFields fields = ps.getAcroFields();
//                fields.setSubstitutionFonts(fontList);
//
//                //备案号
//                fields.setField("recordCode", feedbackMatters.getRecordCode());
//                //申报企业
//                fields.setField("unitName", feedbackMatters.getUnitName());
//                //来文主要内容
//                fields.setField("communicationContent", feedbackMatters.getCommunicationContent());
//                //需要反馈事项
//                fields.setField("mattersDetails", mattersDetails);
//                //备案意见
//                fields.setField("recordMatters", feedbackMatters.getRecordMatters());
//
//                /* 必须要调用这个，否则文档不会生成的 */
//                ps.setFormFlattening(true);
//                ps.close();
//                File dir = new File(model.getParent());
//                File file = File.createTempFile(DateUtil.formatDateTime(new Date()) + matters.getYear() + matters.getUnitName() + "全面预算业务备案表", ".pdf", dir);
//                OutputStream fos = new FileOutputStream(file);
//                fos.write(bos.toByteArray());
//                //写服务器路径
//                String realPath = environment.getProperty("doc.path") + matters.getId();
//                saveFileToServer(file, realPath, DateUtil.formatDateTime(new Date()) + matters.getYear() + matters.getUnitName() + "全面预算业务备案表.pdf", feedbackMatters);
//
//                fos.flush();
//                fos.close();
//                bos.close();
//            }
//
//        } catch (Exception e) {
//            log.error(ExceptionUtils.getFullStackTrace(e));
//        }
//    }
//
//    /**
//     * 写到服务器路径
//     *
//     * @param sourceFile
//     * @param targetDirectory
//     * @param targetFileName
//     * @param feedbackMatters
//     * @throws IOException
//     */
//    private void saveFileToServer(File sourceFile, String targetDirectory, String targetFileName, FullBudgetFeedbackMatters feedbackMatters) throws IOException {
//        // 目标文件夹路径
//        Path targetDirectoryPath = Paths.get(targetDirectory);
//        // 如果目标文件夹不存在，则创建它
//        if (!Files.exists(targetDirectoryPath)) {
//            Files.createDirectories(targetDirectoryPath);
//        }
//        // 目标文件路径
//        Path targetFilePath = targetDirectoryPath.resolve(targetFileName);
//        // 将文件复制到目标路径
//        Files.copy(sourceFile.toPath(), targetFilePath, StandardCopyOption.REPLACE_EXISTING);
//        System.out.println("文件保存成功，路径：" + targetFilePath);
//
//        //保存到附件表
//        InputStream input = new FileInputStream(sourceFile);
//        MultipartFile multipartFile = new MockMultipartFile(sourceFile.getName(), sourceFile.getName(), "application/octet-stream", input);
//        List<HashMap> listDoc = new ArrayList<>();
//        HashMap<String, Object> doc = new HashMap<>();
//        doc.put("itFileName", targetFileName);
//        doc.put("filePath", targetDirectory);
//        doc.put("fileSize", multipartFile.getSize());
//        doc.put("mime", "application/pdf");
//        doc.put("ext", "pdf");
//        listDoc.add(doc);
//
//        //多次生成备案表将原有的删除，再保存
//        PageData pd = new PageData();
//        pd.put("parentId", feedbackMatters.getId());
//        ObjResult objResult = fileService.listParentId(pd);
//        if (objResult.getCode() == 1000) {
//            List<PageData> list_doc = (List<PageData>) objResult.getPageData().get("list_doc");
//            if (list_doc.size() >= 1) {
//                try {
//                    List<String> ids = list_doc.stream().map(e -> e.getString("parentId")).collect(Collectors.toList());
//                    fileDao.delByParentIds(ids);
//                } catch (Exception e) {
//                    throw new RuntimeException(e);
//                }
//            }
//            //保存附件内容
//            fileService.saveAll(String.valueOf(feedbackMatters.getId()), listDoc);
//            log.info("success:保存附件成功...");
//        }
//    }
//
//    @Override
//    public File exportWord(FullBudgetFeedbackMattersVO feedbackMattersVO, HttpServletResponse response) {
//
//        FullBudgetFeedbackMatters feedbackMatters = getById(feedbackMattersVO.getId());
//        File file = null;
//        try {
//            if (Optional.ofNullable(feedbackMatters).isPresent()) {
//
//                String mattersDetails = "";
//                List<FullBudgetFeedbackMattersDetail> fullBudgetFeedbackMattersDetails = mattersDetailMapper.selectList(new LambdaQueryWrapper<FullBudgetFeedbackMattersDetail>()
//                        .eq(FullBudgetFeedbackMattersDetail::getMid, feedbackMattersVO.getId()));
//                if (CollectionUtil.isNotEmpty(fullBudgetFeedbackMattersDetails)) {
//                    List<String> feedMatters = fullBudgetFeedbackMattersDetails.stream().map(FullBudgetFeedbackMattersDetail::getFeedbackMatters).collect(Collectors.toList());
//                    mattersDetails = Joiner.on(";\n").join(feedMatters);
//                }
//
//
//                Map<String, String> data = new HashMap<>();
//                data.put("recordCode", "备案号：" + feedbackMatters.getRecordCode());
//                data.put("unitName", feedbackMatters.getUnitName());
//                data.put("communicationContent", feedbackMatters.getCommunicationContent());
//                data.put("mattersDetails", mattersDetails);
//                data.put("recordMatters", feedbackMatters.getRecordMatters());
//
//                String realPath = environment.getProperty("doc.path") + feedbackMattersVO.getId();
//                //模版
//                InputStream demo = this.getClass().getResourceAsStream("/pdf/full_budget_business.docx");
//
//                file = WordUtil.downloadReportFile(data, realPath, "full_budget_business.docx", demo);
//                response.setHeader("Content-Disposition", "attachment;fileName=" + file.getName());
//                InputStream inputStream = new FileInputStream(file);
//                // 激活下载操作
//                OutputStream os = response.getOutputStream();
//                // 循环写入输出流
//                byte[] b = new byte[2048];
//                int length;
//                while ((length = inputStream.read(b)) > 0) {
//                    os.write(b, 0, length);
//                }
//                // 这里主要关闭。
//                os.close();
//                inputStream.close();
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//
//        return file;
//    }
//
//
//    @Override
//    public File previewPdf(FullBudgetFeedbackMattersVO feedbackMattersVO) {
//        File file = null;
//        try {
//            if (feedbackMattersVO != null && !"".equals(feedbackMattersVO)) {
//
//                String mattersDetails = "";
//                List<FullBudgetFeedbackMattersDetailVO> fullBudgetFeedbackMattersDetails = feedbackMattersVO.getMattersDetails();
//                if (CollectionUtil.isNotEmpty(fullBudgetFeedbackMattersDetails)) {
//                    List<String> feedMatters = fullBudgetFeedbackMattersDetails.stream().map(FullBudgetFeedbackMattersDetail::getFeedbackMatters).collect(Collectors.toList());
//                    mattersDetails = Joiner.on(";\n").join(feedMatters);
//                }
//
//                ResourceLoader resourceLoader = new DefaultResourceLoader();
//                File model = File.createTempFile("logo", ".pdf");
//
//                //准备pdf
//                FileUtils.copyInputStreamToFile(resourceLoader.getResource("/pdf/full_budget_business.pdf").getInputStream(), model);
//
//                String fileName = model.getPath();
//                PdfReader reader = new PdfReader(fileName);
//                ByteArrayOutputStream bos = new ByteArrayOutputStream();
//                /* 将要生成的目标PDF文件名称 */
//                PdfStamper ps = new PdfStamper(reader, bos);
//                /* 使用中文字体 */
//                BaseFont bf = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
//                ArrayList<BaseFont> fontList = new ArrayList<BaseFont>();
//                fontList.add(bf);
//
//                /* 取出报表模板中的所有字段 */
//                AcroFields fields = ps.getAcroFields();
//                fields.setSubstitutionFonts(fontList);
//
//                //备案号
//                fields.setField("recordCode", StringUtil.isNotBlank(feedbackMattersVO.getRecordCode()) ? feedbackMattersVO.getRecordCode() : "");
//                //申报企业
//                fields.setField("unitName", feedbackMattersVO.getUnitName());
//                //来文主要内容
//                fields.setField("communicationContent", feedbackMattersVO.getCommunicationContent());
//                //需要反馈事项
//                fields.setField("mattersDetails", mattersDetails);
//                //备案意见
//                fields.setField("recordMatters", feedbackMattersVO.getRecordMatters());
//
//                /* 必须要调用这个，否则文档不会生成的 */
//                ps.setFormFlattening(true);
//                ps.close();
//                File dir = new File(model.getParent());
//                file = File.createTempFile("宁波市国资委全面预算业务备案表", ".pdf", dir);
//                OutputStream fos = new FileOutputStream(file);
//                fos.write(bos.toByteArray());
//                fos.flush();
//                fos.close();
//                bos.close();
//            }
//
//        } catch (Exception e) {
//            log.error(ExceptionUtils.getFullStackTrace(e));
//        }
//        return file;
//    }
//
//    /**
//     * 详情
//     *
//     * @param budgetFeedbackMattersVO
//     * @return com.plian.system.vo.fr.budgetfeedback.FullBudgetFeedbackMattersVO
//     **/
//    @Override
//    public R detail(FullBudgetFeedbackMattersVO budgetFeedbackMattersVO) {
//
//        FullBudgetFeedbackMattersDTO fullBudgetFeedbackMattersDTO = new FullBudgetFeedbackMattersDTO();
//        List<FullBudgetFeedbackMattersDetail> details = new ArrayList<>();
//        Long id = budgetFeedbackMattersVO.getId();
//        String reportId = budgetFeedbackMattersVO.getReportId();
//        List<FullBudgetFeedbackMatters> fullBudgetFeedbackMatters = new ArrayList<>();
//        if (id != null) {
//            /**
//             * 列表查询详情
//             **/
//            FullBudgetFeedbackMatters matters = baseMapper.selectOne(new LambdaQueryWrapper<FullBudgetFeedbackMatters>()
//                    .eq(FullBudgetFeedbackMatters::getId, id));
//
//            BeanUtils.copyProperties(matters, fullBudgetFeedbackMattersDTO);
//            if (StringUtil.isBlank(reportId)) {
//                reportId = matters.getReportId();
//            }
//
//            //id为空时查询所有的
//            fullBudgetFeedbackMatters = baseMapper.selectList(new LambdaQueryWrapper<FullBudgetFeedbackMatters>()
//                    .eq(FullBudgetFeedbackMatters::getId, id));
//
//        } else {
//
//            fullBudgetFeedbackMatters = baseMapper.selectList(new LambdaQueryWrapper<FullBudgetFeedbackMatters>()
//                    .eq(FullBudgetFeedbackMatters::getReportId, reportId)
//                    .eq(FullBudgetFeedbackMatters::getStatus, BudgetFeedbackMattersConstant.BUDGET_NOT_AGGREGATED));
//
//        }
//
//        if (CollectionUtil.isNotEmpty(fullBudgetFeedbackMatters)) {
//            List<FullBudgetFeedbackMatters> totalList = fullBudgetFeedbackMatters;
//            if (CollectionUtil.isNotEmpty(totalList)) {
//                List<Long> ids = totalList.stream().map(FullBudgetFeedbackMatters::getId).collect(Collectors.toList());
//                List<FullBudgetFeedbackMattersDetail> currDetails = mattersDetailMapper.selectList(new LambdaQueryWrapper<FullBudgetFeedbackMattersDetail>()
//                        .in(FullBudgetFeedbackMattersDetail::getMid, ids).eq(FullBudgetFeedbackMattersDetail::getIsDeleted, 0));
//
//                //查询附件信息
//                for (FullBudgetFeedbackMattersDetail detail : currDetails) {
//                    List<HashMap> docList = new ArrayList<>();
//                    try {
//                        List<PageData> list = fileDao.findParentId(detail.getId().toString());
//                        list.forEach(e -> {
//                            docList.add(e);
//                        });
//                        detail.setDocList(docList);
//                    } catch (Exception e) {
//                        throw new RuntimeException(e);
//                    }
//                }
//                //按照id倒叙排列
//                details = currDetails.stream().sorted(Comparator.comparing(FullBudgetFeedbackMattersDetail::getCreateTime).reversed()).collect(Collectors.toList());
//
//
//            }
//        }
//        fullBudgetFeedbackMattersDTO.setMattersDetails(details);
//
//        return R.data(fullBudgetFeedbackMattersDTO);
//
//    }
//
//    /**
//     * 保存完忽略预算填报消息
//     */
//    private void setIgnoreMessage(FullBudgetFeedbackMattersVO mattersVO) {
//
//        String budgetFillYear = mattersVO.getBudgetFillYear();
//        String budgetFillSummaryCode = mattersVO.getBudgetFillSummaryCode();
//
//        if (StringUtil.isNotBlank(budgetFillYear) && StringUtil.isNotBlank(budgetFillSummaryCode)) {
//            List<Message> messageList = messageService.list(new LambdaQueryWrapper<Message>().eq(Message::getBudgetFillYear, budgetFillYear)
//                    .eq(Message::getBudgetFillSummaryCode, budgetFillSummaryCode));
//            if (CollectionUtil.isNotEmpty(messageList)) {
//                log.info("消息条数--" + messageList.size());
//                messageList.forEach(e -> {
//                    messageService.ignore(e.getId());
//                    log.info("success:消息忽略成功！");
//                });
//            }
//        }
//
//    }
//
//    @Override
//    public R enterpriseSend(FullBudgetFeedbackMattersVO budgetFeedbackMattersVO) {
//
//        FullBudgetFeedbackMatters fullBudgetFeedbackMatters = baseMapper.selectOne(new LambdaQueryWrapper<FullBudgetFeedbackMatters>()
//                .eq(FullBudgetFeedbackMatters::getId, budgetFeedbackMattersVO.getId())
//                .eq(FullBudgetFeedbackMatters::getReportId, budgetFeedbackMattersVO.getReportId()));
//        if (fullBudgetFeedbackMatters != null) {
//            fullBudgetFeedbackMatters.setStatus(BudgetFeedbackMattersConstant.BUDGET_ALREADY_FEEDBACK);
//            baseMapper.updateById(fullBudgetFeedbackMatters);
//            //给财管处发消息
//            sendFinancialMangMessage(fullBudgetFeedbackMatters);
//            return R.success();
//        }
//        return R.error();
//
//    }
//
//    @Override
//    public R deliveryMatters(FullBudgetFeedbackMattersVO budgetFeedbackMattersVO) {
//        FullBudgetFeedbackMatters fullBudgetFeedbackMatters = baseMapper.selectOne(new LambdaQueryWrapper<FullBudgetFeedbackMatters>()
//                .eq(FullBudgetFeedbackMatters::getId, budgetFeedbackMattersVO.getId()));
//        if (fullBudgetFeedbackMatters != null) {
//            if (BudgetFeedbackMattersConstant.BUDGET_NOT_AGGREGATED.equals(fullBudgetFeedbackMatters.getStatus())) {
//                return R.data("财管处暂未汇总！");
//            }
//
//            PageData filingCode = formCodeService.getNoFormatFilingCode((FormTypeConstant.FULL_BUDGET_FEEDBACK_MATTERS_GZ));
//            if (filingCode != null) {
//                String recode = "邢国资财评预备字(" + filingCode.getString("year") + ")" + filingCode.getString("codeNumber") + "号";
//                fullBudgetFeedbackMatters.setRecordCode(recode);
//            }
//            fullBudgetFeedbackMatters.setRecordTime(new Date());
//            //保存下发
//            fullBudgetFeedbackMatters.setStatus(BudgetFeedbackMattersConstant.BUDGET_ALREADY_ISSUED);
//            fullBudgetFeedbackMatters.setDeliveryTime(new Date());
//            //下发消息
//            sendCompanyMessage(fullBudgetFeedbackMatters);
//            baseMapper.updateById(fullBudgetFeedbackMatters);
//            try {
//                //pdf重新生成生成备案表附件，填充备案号
//                downPdf(fullBudgetFeedbackMatters);
//            } catch (Exception e) {
//                log.error("error:备案表生成失败！{}", e);
//            }
//            return R.success();
//        }
//        return R.error();
//    }
//
//    @Override
//    public boolean deleteLogic(List<Long> ids) {
//        for (Long id : ids) {
//            FullBudgetFeedbackMatters feedbackMatters = getById(id);
//            if (feedbackMatters == null) {
//                return false;
//            } else if (feedbackMatters.getStatus() != null &&
//                    (feedbackMatters.getStatus() != FormStatusConstant.STASH && feedbackMatters.getStatus() != FormStatusConstant.UNREVIEWED)) {
//                return false;
//            }
//            formWorkflowService.deleteProcessInstance(String.valueOf(id));
//        }
//        return super.deleteLogic(ids);
//    }
//}
